//
//  ApeHTTPService.h
//  ApeMVPresenter
//
//  Created by Eton on 2017/7/12.
//  Copyright © 2017年 王-庭协. All rights reserved.
//

#import <Foundation/Foundation.h>
@class RACSignal;
@class AFHTTPSessionManager;

typedef NS_ENUM(NSInteger, ApeNetworkType) {
    ApeNetworkTypeNone = -1,
    ApeNetworkTypeWWAN = 1,
    ApeNetworkTypeWiFi
};

//请求类型
typedef NS_ENUM(NSUInteger, ApeMethod) {
    ApeMethod_GET = 0,
    ApeMethod_POST,
    ApeMethod_HEAD,
    ApeMethod_PUT,
    ApeMethod_PATCH,
    ApeMethod_DELETE
};

//缓存类型
typedef NS_ENUM(NSUInteger, ApeCachePolicy){
    ApeCachePolicy_IGNORING_CACHE_DATA = 0, ///< 忽略缓存，重新请求，数据也不做保存（默认）
    ApeCachePolicy_DATA_THEN_LOAD,///< 有缓存就先返回缓存，同步请求数据
    ApeCachePolicy_DATA_DONT_LOAD,///< 有缓存就用缓存，没有缓存就不发请求，当做请求出错处理（用于离线模式）
};

@interface ApeHTTPService : NSObject

+ (ApeHTTPService *)service;

- (instancetype)initWithBaseURL:(NSURL *)URL;

@property (nonatomic, strong, readonly) AFHTTPSessionManager * manager;

//HEADER
@property (nonatomic, strong) NSDictionary <NSString *, NSString *> *HTTPHeaders;

- (void)addHTTPHeader:(NSString *)value key:(NSString *)key;

//可接受的内容类型
@property (nonatomic, copy) NSSet <NSString *> *acceptableContentTypes;

/*需先调用"startMonitoringNetwork"*/
@property(nonatomic, assign) ApeNetworkType netType;

/*监听网络状态，异步获取网络类型*/
- (RACSignal *)startMonitoringNetwork;

/**
 *  GET 请求数据.
 *  缓存机制: ApeCachePolicy_IGNORING_CACHE_DATA.
 */
- (RACSignal *)racGET:(NSString *)url
               params:(NSDictionary *)params
                class:(Class)clazz;

/**
 *  POST 请求数据.
 *  缓存机制: ApeCachePolicy_IGNORING_CACHE_DATA.
*/

- (RACSignal *)racPOST:(NSString *)url
                params:(NSDictionary *)params
                 class:(Class)clazz;

/**
 *  通用方法 请求数据.
 */

- (RACSignal *)racMethod:(ApeMethod )method
                     url:(NSString *)url
                  params:(NSDictionary *)params
                   class:(Class)clazz
             cachePolicy:(ApeCachePolicy )cachePolicy;

/**
 *  POST 请求上传.
 */
- (RACSignal *)racFormData:(NSString *)url
                    params:(id)params
                 mediaData:(NSMutableArray *)mediaDatas;

@end
